package algorithm;

public class leetcode_0081 {
    public boolean search(int[] nums, int target) {
        int len=nums.length;
        int k=0;
        for(int i=0;i<len-1;++i){
            if(nums[i]>nums[i+1]) k=i+1;
        }
        return binarysearch(nums,target,k,k+len,len);
    }
    public boolean binarysearch(int [] nums,int target,int left,int right,int len){
        if(left>=right) return false;
        int mid=(left+right)/2;
        if(nums[mid%len]<target) return binarysearch(nums,target,mid+1,right,len);
        else if(nums[mid%len]==target) return true;
        else{
            return binarysearch(nums,target,left,mid,len);
        }
    }
}
